import fetch from './fetch'

/**
 *
 * @methods [get] params
 * @methods [post] data
 * @methods [delete] 动态路由参数
 * @methods [put] 动态路由参数
 */

// interface DataType {
//   username: string,
//   password: string,
//   _page: string,
//   _limit: string
// }

interface DataType {
  [key: string]: string | number
}

const koaBaseUrl = 'http://localhost:3000/api'
const jsonBaseUrl = 'http://localhost:9999/api'

// 1. 登陆接口
export const fetchLogin = (data: DataType) => {
  return fetch.post(`${koaBaseUrl}/api/login`, data)
}

// 2. 用户管理-列表查询接口-分页接口 get
export const fetchUserList = (params: DataType) => {
  return fetch.get(`${koaBaseUrl}/users`, { params })
}

// 3. 列表搜索接口 条件搜索 get
export const fetchUserSearch = (params: DataType) => {
  return fetch.get(`${jsonBaseUrl}/users`, { params })
}

// 模糊搜索 username_like = '元'，
export const fetchUserFuzzySearch = (params: DataType) => {
  return fetch.get(`${jsonBaseUrl}/users`, { params })
}

// 4. 删除接口 delete
export const fetchUserDelete = (data: DataType) => {
  return fetch.delete(`${koaBaseUrl}/users/${data.id}`)
}

// 5. 更新接口 put/patch { id: 1, username: "", ...}
export const fetchUserUpdate = (data: DataType) => {
  return fetch.put(`${koaBaseUrl}/users/${data.id}`, data)
}
// 6. 多表联查 get  _embed=blogs
export const fetchUserAndBlogs = (params: DataType) => {
  return fetch.put(`${jsonBaseUrl}/users`, params)
}
